﻿<%@ Page Language="C#" MasterPageFile="~/manager/page/ManagerMasterPage.Master" AutoEventWireup="true" CodeBehind="recommend.aspx.cs" Inherits="Com.Web.coffinegurunaru.manager.menu.recommend" %>
<%@ Register TagPrefix="UC" TagName="Menu" Src="~/manager/menu/menu.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="phContent" runat="server">
<hr />
<br />
<table>
<tr>
	<td valign="top">
<UC:Menu ID="Menu1" SubPageType=2 runat="server" />
	</td>
	<td style="width:20px;"></td>
	<td>
<table cellpadding="0" cellspacing="1" style="background-color:Gray; width:100%;">
<tr>
	<td style="background-color:Silver; text-align:center; width:150px; height:30px;">카테고리</td>
	<td style="background-color:#ffffff; ">&nbsp;
		<select id="selCategory" style="width:200px">
			<option value="4">New</option>
			<option value="5">Best</option>
			<option value="2">Season Special</option>
			<option value="3">MD&Cake</option>
			
		</select>
	</td>
</tr>
</table>
<br />
<table cellpadding="0" cellspacing="1" style="background-color:Gray; width:100%;" id="m_RecommendAdd">
<tr>
	<td style="background-color:Silver; text-align:center; width:150px; height:25px;">이미지</td>
	<td style="background-color:#ffffff;">&nbsp;&nbsp;<input type="text" class="m_Image" readonly="readonly" /><input type="button" class="m_btnImage" value="이미지업로드"/></td>
</tr>
<tr>
	<td style="background-color:Silver; text-align:center; height:25px;">링크</td>
	<td style="background-color:#ffffff;">&nbsp;&nbsp;<input type="text" class="m_Link" style="width:300px;"/></td>
</tr>
<tr>
	<td style="background-color:Silver; text-align:center; height:25px;">링크타입</td>
	<td style="background-color:#ffffff;">&nbsp;&nbsp;
		<select style="width:200px" class="m_LinkType">
			<option value="0">링크없음</option>
			<option value="1">현재창</option>
			<option value="2">새창</option>
		</select>
	</td>
</tr>
<tr>
	<td style="background-color:Silver; text-align:center; height:25px;">설명</td>
	<td style="background-color:#ffffff;">&nbsp;&nbsp;<textarea cols="40" rows="3" class="m_Desc" ></textarea></td>
</tr>
<tr>
	<td colspan="2" style="background-color:#ffffff; text-align:center;"><input type="button" id="m_RecommendAdd" class="m_RecommendAdd" value="등록" /></td>
</tr>
</table>
<br />

<table width="100%">
<tr>
	<td align="center">
		<div id="m_RecommendList" ></div>
	</td>
</tr>
</table>

	</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
(function($)
{
	$.Recommend = {}
	
	$.Recommend = {
		ImageBox : null,
		Init : function()
		{
			$("#selCategory").change(function() { $.Recommend.GetList(); });
			
			$("#m_RecommendAdd input.m_btnImage").click(function() {
				$.manager.fileopen(4, "$.Recommend.Image_Add" );
			});
			
			$("#m_RecommendAdd input.m_RecommendAdd").click(function() {
				$.Recommend.Create();
			});

			$.Recommend.GetList();
		},
		
		Image_Add : function( imageurl ) {
			$("#m_RecommendAdd input.m_Image").val( imageurl );
		},
		
		Image_Modify : function( imageurl ) {
			$.Recommend.ImageBox.val( imageurl );
		},
		
		Create : function()
		{
			var CategoryNo = $("#selCategory").val();
			var ImageURL = $("#m_RecommendAdd input.m_Image").val();
			var Link = $("#m_RecommendAdd input.m_Link").val();
			var LinkType = $("#m_RecommendAdd select.m_LinkType").val();
			var Desc = $("#m_RecommendAdd textarea.m_Desc").val();
			
			$("#m_RecommendAdd").ajaxNet(
			"/manager/menu/recommendMethod.aspx?_vb=Create",
			{
				"CategoryNo" : CategoryNo,
				"ImageURL" : ImageURL,
				"Link" : Link,
				"LinkType" : LinkType,
				"Desc" : Desc
			}, function(results, context)
			{
				alert('등록되었습니다.');
				location.href = location.href;
				//$.Recommend.GetList();
			});
		},
		
		Modify : function( $tr )
		{
			var data = $tr.tagdata();
			var ImageURL = $tr.find("input.m_ImageURL").val();
			var Link = $tr.find("input.m_Link").val();
			var LinkType = $tr.find("select.m_LinkType").val();
			var Desc = $tr.find("textarea.m_Desc").val();
			
			$("#m_RecommendAdd").ajaxNet(
			"/manager/menu/recommendMethod.aspx?_vb=Modify",
			{
				"SeqNo" : data.SeqNo,
				"ImageURL" : ImageURL,
				"Link" : Link,
				"LinkType" : LinkType,
				"Desc" : Desc
			}, function(results, context)
			{
				alert('수정되었습니다.');
				location.href = location.href;
				//$.Recommend.GetList();
			});
		},
		
		GetList : function() {
			var CategoryNo = $("#selCategory").val();
			$("#m_RecommendAdd").ajaxNet(
			"/manager/menu/recommendMethod.aspx?_vb=GetList",
			{
				"CategoryNo" : CategoryNo,
				"PageNo" : 1,
				"PageSize" : 20
			}, function(results, context)
			{
				$("#m_RecommendList").html( results );
				
				
				$("#m_RecommendList input.m_btRemove").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$.Recommend.Remove( data.SeqNo );
				});
				
				$("#m_RecommendList input.m_btModifyConfirm").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$.Recommend.Modify( $tr );
				});
				
				$("#m_RecommendList input.m_btModify").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$tr.hide();
					$("#m_RecommendList tr.m_RecommendInput_" + data.SeqNo).show();
				});
				
				$("#m_RecommendList input.m_btModifyCancel").click(function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();
					$tr.hide();
					$("#m_RecommendList tr.m_RecommendInfo_" + data.SeqNo).show();
				});
				
				$("#m_RecommendList input.m_btnImage").click( function() {
					var $tr = $(this).closest("tr");
					var data = $tr.tagdata();

					$.Recommend.ImageBox = $("#m_RecommendList input.m_ImageURL");
					$.manager.fileopen(4, "$.Recommend.Image_Modify" );
				});
			});
		},
		
		Remove : function( SeqNo ) {
			if ( confirm( "정말로 삭제하시겠습니까?" ) ) {
				$("#m_RecommendAdd").ajaxNet(
				"/manager/menu/recommendMethod.aspx?_vb=Remove",
				{
					"SeqNo" : SeqNo
				}, function(results, context)
				{
					$.Recommend.GetList();
				});
			}
		}
	}
	
	$(function() {
		$.Recommend.Init();
	});
})(jQuery);

</script>
</asp:Content>
